<!--在建项目考察情况-->

<template>
  <div>
    <div
      :bordered="false"
      style="over-flow:scroll"
    >
      <div>
        <a-row>
          <!--          <a-table :md="24" :sm="19">-->
          <div class="table-operator">
            <a-row>
              <a-col
                :md="24"
                :sm="24"
              >
                <a-button
                  v-if="type=='add' || type=='edit'|| type=='share'"
                  type="primary"
                  @click="goAdd('add')"
                >新增考察项目</a-button>
                <a-button
                  v-if="type=='add' || type=='edit'|| type=='share'"
                  type="info"
                  :disabled="groupList.length == 0"
                  @click="goDel()"
                >删除</a-button>
              </a-col>
            </a-row>
          </div>

          <a-table
            :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            :columns="columns"
            bordered
            :data-source="groupList"
          >

            <span
              slot="serial"
              slot-scope="text, record, index"
            >{{ index + 1 }}</span>

            <span
              slot="action"
              slot-scope="text, record"
            >
              <template>
                <a
                  v-if="type=='add' || type=='edit'|| type=='share'"
                  @click="handleEdit(record,'edit')"
                >编辑</a>
                <a
                  v-if="type === 'view'"
                  @click="handleView(record,'view')"
                >查看</a>
              </template>
            </span>
          </a-table>
        </a-row>
      </div>
    </div>
    <a-modal
      width="1000px"
      v-model="visible"
      :title="title"
    >
      <template slot="footer">
        <a-button
          key="back"
          @click="handleCancel"
        >
          取消
        </a-button>
        <a-button
          :disabled="type=='view'"
          key="submit"
          type="primary"
          :loading="loading"
          @click="handleOk"
        >
          确定
        </a-button>
      </template>

      <title-name title="项目基本信息"></title-name>
      <a-form-model
        :model="form"
        ref="ruleForm"
        :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
        :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
      >
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="项目名称"
              prop="projectName"
            >
              <BaseInput
                :disabled="type =='view'"
                v-model="form.projectName"
                :maxLength="30"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="工程所在地"
              prop="address"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.address"
                :maxLength="30"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="总承包单位名称"
              prop="name"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.name"
                :maxLength="30"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="总承包单位现场负责人及电话"
              prop="nameAndPhone"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.nameAndPhone"
                :maxLength="30"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="监理单位/开发商"
              prop="developers"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.developers"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="监理单位/开发商现场负责人及电话"
              prop="developersAndPhone"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.developersAndPhone"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="承包内容及规模"
              prop="contentAndSize"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.contentAndSize"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="被考察分包商现场负责人及电话"
              prop="subcontractorNameAndPhone"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.subcontractorNameAndPhone"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="当前施工内容"
              prop="constrctionContent"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.constrctionContent"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="现场劳动力人数"
              prop="count"
            >
              <BaseInputNumber
                type="number"
                :disabled="type=='view'"
                v-model="form.count"
                :formatter="limitNumber"
                :parser="limitNumber"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>

      <title-name title="现场效果"></title-name>
      <a-form-model
        :model="form"
        ref="ruleForm"
        :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
        :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }"
      >
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="安全效果"
              prop="security"
            >
              <!-- <a-radio-group :disabled="type==='view'" v-model="form.security">
                <a-radio v-for="item in statusList" :key="item.id">{{item.name}}</a-radio>
              </a-radio-group> -->
              <a-radio-group
                :disabled="type=='view'"
                v-model="form.security"
                :options="statusList"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="安全亮点"
              prop="securityAdvantage"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.securityAdvantage"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="安全不足"
              prop="securityShortcoming"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.securityShortcoming"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="文明施工效果"
              prop="civilization"
            >
              <!-- <a-radio-group :disabled="type==='view'" v-model="form.civilization" name="radioGroup" >
                <a-radio :value="1">
                  好
                </a-radio>
              </a-radio-group> -->
              <a-radio-group
                :disabled="type=='view'"
                v-model="form.civilization"
                :options="statusList"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="文明施工亮点"
              prop="civilizationAdvantage"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.civilizationAdvantage"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="文明施工不足"
              prop="civilizationShortcoming"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.civilizationShortcoming"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="质量效果"
              prop="quality"
            >
              <a-radio-group
                :disabled="type=='view'"
                v-model="form.quality"
                :options="statusList"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="质量亮点"
              prop="qualityAdvantage"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.qualityAdvantage"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="质量不足"
              prop="qualityShortcoming"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.qualityShortcoming"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="其他效果"
              prop="elseMore"
            >
              <a-radio-group
                :disabled="type=='view'"
                v-model="form.elseMore"
                :options="statusList"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
        <a-row>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="其他亮点"
              prop="elseAdvantage"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.elseAdvantage"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
          <a-col
            :md="12"
            :sm="12"
          >
            <a-form-model-item
              label="其他不足"
              prop="elseShortcoming"
            >
              <BaseInput
                :disabled="type=='view'"
                v-model="form.elseShortcoming"
                placeholder="请输入"
              />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-modal>
  </div>
</template>

<script>
import { STable } from '@/components'
import { getConstructionList, addConstructionList, editConstructionList, deleteConstructionList } from '@/api/subcontractors/labour'
import { getStatusCodeData } from '@/api/subcontractors/labor'

const columns = [
  {
    title: '序号',
    width: 65,
    scopedSlots: { customRender: 'serial' }
  },
  {
    title: '项目名称',
    dataIndex: 'projectName',
    ellipsis: true
  },
  {
    title: '工程所在地',
    dataIndex: 'address',
    ellipsis: true
  },
  {
    title: '总承包单位名称',
    dataIndex: 'name',
    ellipsis: true
  },
  {
    title: '承包内容及规模',
    dataIndex: 'contentAndSize',
    ellipsis: true
  },
  {
    title: '现场劳动力人数',
    dataIndex: 'count',
    ellipsis: true
  },
  {
    title: '现场安全效果',
    dataIndex: 'security',
    ellipsis: true
  },
  {
    title: '现场文明施工效果',
    dataIndex: 'civilization',
    ellipsis: true
  },
  {
    title: '现场质量效果',
    dataIndex: 'quality',
    ellipsis: true
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: '150px',
    scopedSlots: { customRender: 'action' }
  }
]
export default {
  name: 'a' + Date.now(),

  components: {},
  props: {
    labourList: {
      type: [Object, Array],
      default() {
        return {}
      }
    }
  },
  data() {
    this.columns = columns
    return {
      visible: false,
      type: '',
      title: '',
      id: '',
      statusList: [],
      loading: false,
      lists: {},
      form: {
        security: '',
        securityAdvantage: '',
        securityShortcoming: '',
        civilization: '',
        civilizationAdvantage: '',
        civilizationShortcoming: '',
        quality: '',
        qualityAdvantage: '',
        qualityShortcoming: '',
        elseMore: '',
        elseAdvantage: '',
        elseShortcoming: '',
        projectName: '',
        address: '',
        name: '',
        type: '',
        nameAndPhone: '',
        developers: '',
        developersAndPhone: '',
        contentAndSize: '',
        subcontractorNameAndPhone: '',
        constrctionContent: '',
        count: ''
      },
      groupList: [],
      selectedRowKeys: [],
      selectedRows: [],
      selectId: [],
      addInvestigateId: ''
    }
  },
  created() {
    this.addInvestigateId = JSON.parse(sessionStorage.getItem('addInvestigateId'))
    this.type = this.$route.query.type
    if (this.type == 'share') {
      this.id = this.addInvestigateId
    } else {
      this.id = this.$route.query.id || this.addInvestigateId
    }
    this.getGroup()
    this.getStatusCodeData()
  },
  methods: {
    onSelectChange(selectedRowKeys, selectedRows) {
      console.log('selectedRows: ', selectedRows)
      console.log('selectedRowKeys changed: ', selectedRowKeys)
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    getGroup() {
      getConstructionList({ id: this.id }).then((res) => {
        this.groupList = res.data
      })
    },
    getStatusCodeData() {
      getStatusCodeData({ type: '12' }).then((res) => {
        this.statusList = res.data
        this.statusList.forEach((item) => {
          item.label = item.name
          item.value = item.id
        })
      })
    },
    search() {
      this.$refs.table.refresh(true)
    },
    goAdd(type) {
      this.type = type
      this.form = {}
      this.visible = true
      this.title = '新增在建项目考察情况'
    },
    goDel() {
      let _this = this
      if (_this.selectedRows.length == 1) {
        this.$confirm({
          title: '警告提醒！',
          content: '确定删除？',
          okType: 'danger',
          onOk() {
            deleteConstructionList({ ids: _this.selectedRows[0].id, lsebId: _this.labourList.subcontractorBase.evaluationId }).then((res) => {
              if (res.code == '200') {
                _this.getGroup()
                _this.$message.success('删除成功')
                _this.selectedRows = []
                _this.selectedRowKeys = []
              }
            })
          },
          onCancel() {
            console.log('Cancel')
          }
        })
      } else if (_this.selectedRows.length > 1) {
        _this.selectId = []
        _this.selectedRows.forEach((item) => {
          _this.selectId.push(item.id)
        })
        this.$confirm({
          title: '警告提醒！',
          content: '确定删除？',
          okType: 'danger',
          onOk() {
            deleteConstructionList({ ids: _this.selectId.join(','), lsebId: _this.labourList.subcontractorBase.evaluationId }).then((res) => {
              if (res.code == '200') {
                _this.getGroup()
                _this.$message.success('删除成功')
                _this.selectedRows = []
                _this.selectedRowKeys = []
              }
            })
          },
          onCancel() {
            console.log('Cancel')
          }
        })
      } else if (_this.selectedRows.length == 0) {
        _this.$message.error('请选择要删除的内容')
      }
    },
    handleView(record, type) {
      this.type = type
      this.visible = true
      this.title = '查看在建项目考察情况'
      this.form = JSON.parse(JSON.stringify(record))
      this.form.security = this.form.securityId
      this.form.civilization = this.form.civilizationId
      this.form.elseMore = this.form.elseMoreId
      this.form.quality = this.form.qualityId
    },
    handleEdit(record, type) {
      this.type = type
      this.visible = true
      this.title = '编辑在建项目考察情况'
      this.lists = record
      this.form = JSON.parse(JSON.stringify(record))
      this.form.security = this.form.securityId
      this.form.civilization = this.form.civilizationId
      this.form.elseMore = this.form.elseMoreId
      this.form.quality = this.form.qualityId
    },
    handleOk() {
      this.visible = false
      this.form.subcontractorId = this.subcontractorId
      this.form.lsebId = this.labourList.subcontractorBase.evaluationId
      if (this.form.id) {
        editConstructionList(this.form).then((res) => {
          if (res.code == '200') {
            this.$message.success('编辑成功')
            this.getGroup()
          }
        })
      } else {
        addConstructionList(this.form).then((res) => {
          if (res.code == '200') {
            this.$message.success('新增成功')
            this.getGroup()
          }
        })
      }
    },
    handleCancel() {
      this.form = this.lists
      this.visible = false
      this.getGroup()
    },
    handleAdd() {},
    limitNumber(value) {
      if (typeof value === 'string') {
        return !isNaN(Number(value)) ? value.replace(/^(0+)|[^\d]/g, '') : ''
      } else if (typeof value === 'number') {
        return !isNaN(value) ? String(value).replace(/^(0+)|[^\d]/g, '') : ''
      } else {
        return ''
      }
    }
  }
}
</script>

<style scoped>
.input {
  width: 100%;
}
/deep/ .ant-table-pagination.ant-pagination {
  display: none;
}
</style>
